package com.tianji.learning.mq;

import com.tianji.api.dto.trade.OrderBasicDTO;
import com.tianji.learning.service.ILearningLessonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.tianji.common.constants.MqConstants.Exchange.ORDER_EXCHANGE;
import static com.tianji.common.constants.MqConstants.Key.ORDER_REFUND_KEY;
import static com.tianji.common.constants.MqConstants.Queue.ORDER_REFUND_COURESE_QUEUE;

/**
 * @param
 * @return
 */
@Slf4j
@Component
public class LisenerCoureseMsg {

    @Autowired
    private ILearningLessonService iLearningLessonService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = ORDER_REFUND_COURESE_QUEUE, durable = "true"),
            exchange = @Exchange(value = ORDER_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = ORDER_REFUND_KEY
    ))
    public void LisenerCouserMsg(OrderBasicDTO orderBasicDTO) {
        log.info("监测到{}的订单，订单编号{}，将退款的课程id为{}"
                , orderBasicDTO.getUserId(), orderBasicDTO.getOrderId(), orderBasicDTO.getCourseIds());
        iLearningLessonService.LessonRefund(orderBasicDTO);
    }
}
